//
//  HDOperationService.m
//  HDOperationProject
//
//  Created by Mirko on 15/10/30.
//  Copyright (c) 2015年 Mirko. All rights reserved.
//

#import "HDOperationService.h"
#import <UIKit/UIKit.h>
#import "HDOperationDataManager.h"
#import "HDOperationTools.h"

static HDOperationService* service = nil;


@interface HDOperationService () <UINavigationControllerDelegate>

//@property (nonatomic, strong) HDOperationDataManager *operationDataMgr;
@property (nonatomic, strong) NSMutableArray *operationIds;
@property (nonatomic, assign) BOOL isGreditGroup;

-(BOOL) needShowOpeartion;

@end

@implementation HDOperationService

+(void) startGreditGroupServiceWithAdURL:(NSString *)urlString block:(HDOperationServiceBlock) block
{
    [[HDOperationDataManager shareManager] setAdURL:urlString];
    [HDOperationService instance].isGreditGroup = YES;
    [[HDOperationService instance] checkOpeationInfo];
    if (block) {
        block([HDOperationService instance].navigationVC);
    }
}

+(void) startHaoDaiServiceWithAdURL:(NSString *)urlString block:(HDOperationServiceBlock) block
{
    [[HDOperationDataManager shareManager] setAdURL:urlString];
    [HDOperationService instance].isGreditGroup = NO;
    [[HDOperationService instance] checkOpeationInfo];

    if (block) {
        block([HDOperationService instance].navigationVC);
    }
}

+(instancetype) instance
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        service = [[HDOperationService alloc] init];
    });
    return service;
}

-(instancetype) init
{
    self = [super init];
    if (self) {
        
//        self.operationDataMgr = [[HDOperationDataManager alloc] init];
        
        
//        [self.operationDataMgr updataOperationActivitiesData];
    }
    return self;
}

// 检测是否需要展示广告页面
-(void) checkOpeationInfo
{
    if ([self needShowOpeartion]) {
        [self createNavigationController];
    }
}

// 创建广告页面控制器
-(void) createNavigationController
{
    NSString *storyboardName = _isGreditGroup ? @"CreditGroupOperation" : @"HDOperation";
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:storyboardName bundle:[MCUtils MCPMBundle]];
    HDOperationViewController *controller = [storyBoard instantiateInitialViewController];
    _navigationVC = [[UINavigationController alloc] initWithRootViewController:controller];
    _operationVC = controller;
}

-(BOOL) needShowOpeartion
{
    return [[HDOperationDataManager shareManager] isNeedShowAd];
    
//    NSString *operationFolder = [HDOperationTools getFolderPath:kOperationFolderTypeRoot operationId:self.operationDataMgr.activitiesData.operationId];
//    return [[NSFileManager defaultManager] fileExistsAtPath:operationFolder isDirectory:nil];
}

@end
